package demo1;

import java.util.List;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //除自身以外数组的乘积
    public int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        int[] ret = new int[n];
        int[] dp1 = new int[n];
        int[] dp2 = new int[n];
        dp1[0] = 1;
        dp2[n-1] = 1;
        for (int i = 1; i < n; i++) {
            dp1[i] = dp1[i-1]*nums[i-1];
        }
        for (int i = n-2; i <= 0 ; i--) {
            dp2[i] = dp2[i+1]*nums[i+1];
        }
        for (int i = 0; i < n; i++) {
            ret[i] = dp1[i]*dp2[i];
        }
        return ret;
    }

    //数组列表中的最大距离
    public int maxDistance(List<List<Integer>> arrays) {
        int max = Integer.MIN_VALUE;
        int n = arrays.size();
        int[] MAX = new int[n];
        int[] MIN = new int[n];
        int count = 0;
        for(List<Integer> list : arrays){
            int len = list.size();
            MIN[count] = list.get(0);
            MAX[count] = list.get(len-1);
            count++;
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(i==j){
                    continue;
                }else {
                    max = Math.max(max,Math.abs(MAX[i]-MIN[j]));
                }
            }
        }
        return max;
    }
}
